import 'package:flutter/material.dart';
import 'package:flutter_app/util/ToastUtil.dart';

///底部弹窗
class BottomSheetWidget extends StatelessWidget {
  final String? text;

  BottomSheetWidget({this.text}) : super();
  List<String> nameItems = <String>[
    '微信',
    '朋友圈',
    'QQ',
    'QQ空间',
    '微博',
    'FaceBook',
    '邮件',
    '链接'
  ];
  List<String> urlItems = <String>[
    'women_one.jpg',
    'women_two.jpg',
    'iron_man.jpg',
    'women_one.jpg',
    'women_two.jpg',
    'iron_man.jpg',
    'women_one.jpg',
    'women_two.jpg'
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(text ?? ""),
      ),
      body: Center(
        child: Builder(builder: (BuildContext context) {
          return TextButton(
              onPressed: () {
                //主要用这个控件
                showModalBottomSheet(
                    context: context,
                    builder: (BuildContext context) {
                      return _showNormalWid(context);
                    });
              },
              child: Text(
                "我要分享",
                style: TextStyle(fontSize: 20),
              ));
        }),
      ),
    );
  }

  Widget _showNormalWid(BuildContext context) {
    return new Container(
      height: 250.0,
      child: new Column(
        children: <Widget>[
          new Padding(
            padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
            child: new Container(
              height: 190.0,
              child: new GridView.builder(
                gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 4,
                    mainAxisSpacing: 5.0,
                    childAspectRatio: 1.0),
                itemBuilder: (BuildContext context, int index) {
                  return GestureDetector(
                    onTap: () {
                      ToastUtil.toastShort(nameItems[index]);
                    },
                    child: new Column(
                      children: <Widget>[
                        new Padding(
                            padding: EdgeInsets.fromLTRB(0.0, 6.0, 0.0, 6.0),
                            child: new Image.asset(
                              'assets/images/${urlItems[index]}',
                              width: 50.0,
                              height: 50.0,
                              fit: BoxFit.fill,
                            )),
                        new Text(nameItems[index])
                      ],
                    ),
                  );
                },
                itemCount: nameItems.length,
              ),
            ),
          ),
          new Container(
            height: 0.5,
            color: Colors.blueGrey,
          ),
          new Center(
            child: new Padding(
              padding: EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0),
              child: GestureDetector(
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                  child: new Text(
                    '取  消',
                    style:
                        new TextStyle(fontSize: 18.0, color: Colors.blueGrey),
                  )),
            ),
          ),
        ],
      ),
    );
  }
}
